// 获取页面数据
var resData = '';
var param   = {'operation':'getUserBankCardList'};
do_post(param);
function do_post(param){
	$.ajax({  
		type:'post',    
	    url: getDataUrl,  
	    data:'data=' + JSON.stringify(param),  
	    cache:false,  
	    dataType:'json', 
	    async:false,
	    success:function(res){  
	    	if(res.msg){
	    		showMsg('温馨提示', res.msg);
	    	}else{
	    		resData = res;
	    	}
	    }  
	})
}
console.log(resData);
// 填充银行卡列表
$('#id_user_bank_list_box').html('');
$('#id_user_bank_list_box').html(function (){
	console.log(resData.bindList.length)
	if($.isEmptyObject(resData.bindList)|| resData.bindList.length<5) {
		var html = '<a tag="div" id="id_check_count" class="cardEmpty cardItem ClickShade" href="?m=member&c=manageBankcard&op=bindcard">立即添加银行卡</a>';
		$('#id_user_bank_list_box').append(html);
	}
	$.each(resData.bindList, function (i, v){
		var str = ' <div class="cardItem" id="id_bindcard_' + v.id + '">';
		str    += '		<div class="bankName">';
		str    += '			<i class="' + v.tags + '"></i>' + v.name;
		str    += '		</div>';
		str    += '		<div class="bankNum">尾号：' + v.rebankcard + '</div>';
		str    += '		<div class="cardInfo fix">';
		str    += '			<div class="cardStyle cardPink">储蓄卡<em></em></div>';
		str    += '			<div class="cardOperation">';
		if(v.status == '0'){
			str    += ' 			<span class="_islock">锁定</span>';
		}else{
			str    += ' 			<span class="_islock">正常</span>';
		}
		str    += ' 			<span><a href = "javascript:void(0);" class="tag_del_bank" ami="' + v.id + '">删除</a></span>';
		str    += ' 		</div>';
		str    += '		</div>';
		str    += ' 	<div class="cardTxt">';
		str    += ' 		<p>绑卡日期：' + v.re_dateline + '</p><p>绑卡姓名：' + v.truename + '</p>';
		str    += ' 	</div>';
		str    += ' </div>';
		$('#id_user_bank_list_box').prepend(str);
	});
});
$('#id_card_count').html(function (){
	if($.isEmptyObject(resData.bindList)){
		return 0;
	}
	return resData.bindList.length;
});

$('#id_user_bank_list_box').on('click', '.tag_del_bank', function (){
	var ami = $(this).attr('ami');
	layer.open({
	    title: '温馨提示',
	    content: '确认要解除该卡绑定？',
	    className: 'layui-m-tag-msg',
	    btn: ['确定'],
	    yes: function (index){
	    	layer.close(index);
	    	// 页面解除该选项框
	    	param  = {'operation':'unBindBankCard', 'bid': ami};
	    	do_post(param);
	    	$('#id_bindcard_' +ami).remove();
	    	if($('#id_check_count').length==0){
	    		var html = '<a tag="div" id="id_check_count" class="cardEmpty cardItem ClickShade" href="?m=member&c=manageBankcard&op=bindcard">立即添加银行卡</a>';
	    		$('#id_user_bank_list_box').append(html);
	    	}
	    },
	    no:function (index){
	    	layer.close(index);
	    }
	})
	var n = $('#id_card_count').html();
	$('#id_card_count').html(--n);
});

function showMsg(title, content){
	layer.open({
        title: title,
        content: content,
        className: 'layui-m-tag-msg',
        btn: ['确定'],
        yes: function (index){
			// 继续投注
        	layer.close(index);
        	
        },
    });
}